home *** CD-ROM | disk | FTP | other *** search
- // WEBSERV.VSC - Version 1.20
- // A skeletal web server written in ObjectViRCScript
-
- Alias STARTWEBSERVER
- @ $webform = $new(TTabbedForm)
- With @p $webform.
- Left = 20
- Top = 300
- Width = 600
- Height = 120
- FormStyle = fsStayOnTop
- Caption = ObjectViRCScript Web Server Example
- TabCaption = Web server
- Visible = True
- EndWith
-
- @ $webpanel = $new(TPanel ownedby $webform)
- With @p $webpanel.
- Height = 25
- Align = alTop
- BevelOuter = bvLowered
- Caption = Listening for connections ...
- Visible = True
- EndWith
-
- @ $webedit = $new(TRichEdit ownedby $webform)
- With @p $webedit.
- Align = alClient
- ReadOnly = True
- Visible = True
- EndWith
-
- @ $websocket = $new(TSockets ownedby $webform)
- With @p $websocket.
- Port = 80
- OnSessionAvailable = WEBSOCKET_INCOMINGCONNECTION
- OnDataAvailable = WEBSOCKET_DATA
- OnSessionClosed = WEBSOCKET_CLOSE
- OnErrorOccurred = Nop
- EndWith
-
- @p $webform.OnClose = WEBSERVER_SHUTDOWN
- @p $webform.OnResize = $webedit.Repaint
-
- $websocket.SListen
-
- TextOut > %$webedit clBlue *** Welcome to the \bViRC '96 web server\b example application.
- EndAlias
-
- Alias WEBSOCKET_INCOMINGCONNECTION
- $websocket.SAccept
- @l $remoteip = $prop($websocket.RemoteIPAddr)
- TextOut > %$webedit clGreen *** Accepting incoming connection from \b$remoteip\b
- @p $webpanel.Caption = Connected to $remoteip.
- EndAlias
-
- Alias WEBSOCKET_DATA
- @l $x = $prop($websocket.Text)
- Parse $upper($x)
- if ([$0] == [GET])
- ChDir $getpath(virc)
- @ $webfile = $substr($1 2 9999)
- if ($fileexists($webfile))
- TextOut > %$webedit clBlue *** Processing request: \b$0 $1\b (success)
- @l $i = $getlinesinfile($webfile)
- for (@l $j = 1; $j <= $i; $j++)
- $websocket.SendCRLF $readline($j $webfile)
- endfor
- $websocket.SClose
- else
- TextOut > %$webedit clBlue *** Processing request: \b$0 $1\b (failure)
- $websocket.SendCRLF <HTML><H1>ViRC '96 - Web server error</H1><P>Cannot find file: <B>$webfile</B></P></HTML>
- $websocket.SClose
- endif
- endif
- EndParse
- EndAlias
-
- Alias WEBSOCKET_CLOSE
- @l $remoteip = $prop($websocket.RemoteIPAddr)
- $websocket.SClose
- TextOut > %$webedit clRed *** Connection closed: \b$remoteip\b
- @p $webpanel.Caption = Disconnected from $remoteip, listening ...
- EndAlias
-
- Alias WEBSERVER_SHUTDOWN
- $websocket.SCancelListen
- Destroy $webform
- EndAlias